package cn.com.nes.site.controller.crm.customer;

import cn.com.nes.common.web.CommonResult;
import cn.com.nes.mybatis.agent.crm.entity.CustomerFile;
import cn.com.nes.site.controller.crm.customer.vo.CustomerFileDelVO;
import cn.com.nes.site.controller.crm.customer.vo.CustomerFilePageVO;
import cn.com.nes.site.controller.crm.customer.vo.CustomerFileSaveVO;
import cn.com.nes.site.service.crm.customer.CustomerFileService;
import cn.com.nes.site.service.crm.customer.dto.CustomerFileDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

@Api(tags = {"销售管理-客户管理-文件管理"})
@Controller
@RequestMapping("/v2/crm/customer/file")
public class CustomerFileController {

    @Resource
    private CustomerFileService customerFileService;

    @ApiOperation(value = "查询客户文件分页")
    @RequestMapping(value = "/getCustomerFilePage", method = RequestMethod.GET)
    public @ResponseBody CommonResult<CustomerFileDTO> getCustomerFilePage(@Validated CustomerFilePageVO customerFilePageVO) throws Exception {
        Page<CustomerFileDTO> customerFilePage = customerFileService.getCustomerFilePage(customerFilePageVO.convertToBo());
        return CommonResult.page(customerFilePage);
    }

    @ApiOperation(value = "保存客户文件")
    @RequestMapping(value = "/saveCustomerFile", method = RequestMethod.POST)
    public @ResponseBody CommonResult<Long> saveCustomerFile(@RequestBody @Validated CustomerFileSaveVO customerFileSaveVO) throws Exception {
        CustomerFile customerFile = customerFileService.saveCustomerFile(customerFileSaveVO.convertToBo());
        return CommonResult.data(customerFile.getId());
    }

    @ApiOperation(value = "删除客户文件")
    @RequestMapping(value = "/delCustomerFile", method = RequestMethod.POST)
    public @ResponseBody CommonResult<?> delCustomerFile(@RequestBody @Validated CustomerFileDelVO customerFileDelVO) throws Exception {
        customerFileService.delCustomerFile(customerFileDelVO.convertToBo());
        return CommonResult.ok();
    }

}
